import { defineStore } from 'pinia'

export const useKeyStore = defineStore('keyStore', () => {
    const keyDownList = new Set()

    /**
     * 判断是否按下了指定的所有按键
     * @param list
     * @returns {boolean}
     */
    function keyDown(list) {
        for (let item of list) {
            if(!keyDownList.has(item)) return false
        }
        return true
    }

    function keyDownAny(list) {
        for (let item of list) {
            if(keyDownList.has(item)) return true
        }
        return false
    }

    function addKeyDown(key) {
        keyDownList.add(key)
    }

    function delKeyDown(key) {
        keyDownList.delete(key)
    }


  return { keyDownList,keyDown,addKeyDown,delKeyDown,keyDownAny }
})
